from django.shortcuts import render,HttpResponse,redirect

# Create your views here.


def wrapper(f):
    def inner(request,*args,**kwargs):
        status = request.session.get('is_login')

        if status:
            ret = f(request,*args,**kwargs)
            return ret
        else:

            return redirect('/login/')


    return inner


# @wrapper
def home(request):
    print('这是home函数')


    return HttpResponse('home')


def login(request):
    if request.method == 'GET':
        print('这是login函数')
        # raise ValueError('xxxx')
        def render():
            print('执行啦！！！！！')
            return HttpResponse('xxxxx')

        ret = HttpResponse('login')
        ret.render = render
        # jasdiojfoajsf
        # return render(request,'login.html')
        return ret

    else:
        username = request.POST.get('username')
        pwd = request.POST.get('password')

        if username == 'chao' and pwd == '123':
            request.session['is_login'] = True
            #request.session
            # 1 生成随机字符串，


            return redirect('/home/')

        else:
            return redirect('/login/')



def index(request):

    print('这是index函数')
    return render(request,'index.html')







